package org.snare.alumni.modules.admin.org.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.snare.alumni.modules.admin.org.entity.OrgEntity;
import org.snare.alumni.modules.admin.org.mapper.OrgMapper;
import org.snare.alumni.modules.admin.org.service.api.OrgService;
import org.snare.spider.common.base.Limit;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class OrgServiceImpl implements OrgService {

    private final OrgMapper orgMapper;

    @Override
    public IPage<OrgEntity> page(String title, String type, Limit limit) {
        return new LambdaQueryChainWrapper<>(orgMapper)
                .eq(StringUtils.isNotBlank(title), OrgEntity::getTitle, title)
                .eq(StringUtils.isNotBlank(type), OrgEntity::getType, type)
                .page(limit.page());
    }

    @Override
    public List<OrgEntity> list(String type) {
        return new LambdaQueryChainWrapper<>(orgMapper).eq(OrgEntity::getType, type).list();
    }

    @Override
    public void add(OrgEntity params) {
        orgMapper.insert(params);
    }

    @Override
    public void edit(OrgEntity params) {
        orgMapper.updateById(params);
    }

    @Override
    public void delete(String id) {
        orgMapper.deleteById(id);
    }

    @Override
    public OrgEntity detail(String id) {
        return new LambdaQueryChainWrapper<>(orgMapper).eq(OrgEntity::getId, id).one();
    }

}
